package utils.verifier;

/**
 * This class contains methods to verify if a special condition is fulfilled and
 * if not throws an exception
 * 
 * @author Joana Otetelisanu
 * @author Marcus Lindner
 */
public enum ArgumentVerifier {
	/** No instance needed. */
	;

	/**
	 * Checks whether the parameter {@code a} is greater {@code b}.
	 * 
	 * <p>
	 * If {@code a} is smaller or equal {@code b} the a new
	 * {@link IllegalArgumentException} will be thrown.
	 * </p>
	 * 
	 * @param a
	 *            parameter a
	 * @param b
	 *            parameter b
	 * @param text
	 *            text for the exception
	 */
	public static void ensureIsGreater(double a, double b, String text) {
		if (a > b) {
			throw new IllegalArgumentException(text);
		}
	}

	/**
	 * Checks whether the parameter {@code a} is greater {@code b}.
	 * 
	 * <p>
	 * If {@code a} is smaller or equal {@code b} the a new
	 * {@link IllegalArgumentException} will be thrown.
	 * </p>
	 * 
	 * @param a
	 *            parameter a
	 * @param b
	 *            parameter b
	 */
	public static void ensureIsGreater(double a, double b) {
		if (a > b) {
			throw new IllegalArgumentException();
		}
	}

	/**
	 * Checks whether the parameter {@code a} is greater or equal {@code b}.
	 * 
	 * <p>
	 * If {@code a} is smaller or not equal {@code b} the a new
	 * {@link IllegalArgumentException} will be thrown.
	 * </p>
	 * 
	 * @param a
	 *            parameter a
	 * @param b
	 *            parameter b
	 * @param text
	 *            text for the exception
	 */
	public static void ensureIsGreaterOrEqual(int a, int b, String text) {
		if (a >= b) {
			throw new IllegalArgumentException(text);
		}
	}

	/**
	 * Checks whether the parameter {@code a} is greater or equal {@code b}.
	 * 
	 * <p>
	 * If {@code a} is smaller or not equal {@code b} the a new
	 * {@link IllegalArgumentException} will be thrown.
	 * </p>
	 * 
	 * @param a
	 *            parameter a
	 * @param b
	 *            parameter b
	 */
	public static void ensureIsGreaterOrEqual(int a, int b) {
		if (a >= b) {
			throw new IllegalArgumentException();
		}
	}

	/**
	 * Checks whether the parameter {@code a} is smaller or equal {@code b}.
	 * 
	 * <p>
	 * If {@code a} greater {@code b} the a new {@link IllegalArgumentException}
	 * will be thrown.
	 * </p>
	 * 
	 * @param a
	 *            parameter a
	 * @param b
	 *            parameter b
	 * @param text
	 *            text for the exception
	 */
	public static void ensureIsSmallerOrEqual(int a, int b, String text) {
		if (a > b) {
			throw new IllegalArgumentException(text);
		}
	}

	/**
	 * Checks whether the parameter {@code a} is smaller or equal {@code b}.
	 * 
	 * <p>
	 * If {@code a} is greater {@code b} the a new
	 * {@link IllegalArgumentException} will be thrown.
	 * </p>
	 * 
	 * @param a
	 *            parameter a
	 * @param b
	 *            parameter b
	 */
	public static void ensureIsSmallerOrEqual(int a, int b) {
		if (a > b) {
			throw new IllegalArgumentException();
		}
	}

	/**
	 * Checks whether the parameter {@code a} is smaller {@code b}.
	 * 
	 * <p>
	 * If {@code a} greater or equal {@code b} the a new
	 * {@link IllegalArgumentException} will be thrown.
	 * </p>
	 * 
	 * @param a
	 *            parameter a
	 * @param b
	 *            parameter b
	 * @param text
	 *            text for the exception
	 */
	public static void ensureIsSmaller(int a, int b, String text) {
		if (a >= b) {
			throw new IllegalArgumentException(text);
		}
	}

	/**
	 * Checks whether the parameter {@code a} is smaller {@code b}.
	 * 
	 * <p>
	 * If {@code a} is greater or equal {@code b} the a new
	 * {@link IllegalArgumentException} will be thrown.
	 * </p>
	 * 
	 * @param a
	 *            parameter a
	 * @param b
	 *            parameter b
	 */
	public static void ensureIsSmaller(int a, int b) {
		if (a >= b) {
			throw new IllegalArgumentException();
		}
	}

	/**
	 * Checks whether the parameter {@code a} equals {@code b}.
	 * 
	 * <p>
	 * If {@code a} does not equal {@code b} the a new
	 * {@link IllegalArgumentException} will be thrown.
	 * </p>
	 * 
	 * @param a
	 *            parameter a
	 * @param b
	 *            parameter b
	 * @param text
	 *            text for the exception
	 */
	public static void ensureIsEqual(int a, int b, String text) {
		if (a != b) {
			throw new IllegalArgumentException(text);
		}
	}

	/**
	 * Checks whether the parameter {@code a} equals {@code b}.
	 * 
	 * <p>
	 * If {@code a} does not equal {@code b} the a new
	 * {@link IllegalArgumentException} will be thrown.
	 * </p>
	 * 
	 * @param a
	 *            parameter a
	 * @param b
	 *            parameter b
	 */
	public static void ensureIsEqual(int a, int b) {
		if (a != b) {
			throw new IllegalArgumentException();
		}
	}

	/**
	 * Checks whether the parameter {@code a} is smaller or equal as {@code 0}.
	 * 
	 * <p>
	 * If {@code a} is smaller or equal {@code 0} the a new
	 * {@link IllegalArgumentException} will be thrown.
	 * </p>
	 * 
	 * @param a
	 *            parameter a
	 * @param text
	 *            text for the exception
	 */
	public static void ensureIsGreaterZero(double a, String text) {
		if (a <= 0) {
			throw new IllegalArgumentException(text);
		}
	}

	/**
	 * Checks whether the parameter {@code a} is smaller or equal as {@code 0}.
	 * 
	 * <p>
	 * If {@code a} is smaller or equal {@code 0} the a new
	 * {@link IllegalArgumentException} will be thrown.
	 * </p>
	 * 
	 * @param a
	 *            parameter a
	 */
	public static void ensureIsGreaterZero(double a) {
		if (a <= 0) {
			throw new IllegalArgumentException();
		}
	}

	/**
	 * Throws an {@link IllegalArgumentException} if the passed object is
	 * {@code null}.
	 * 
	 * @param object
	 *            object which is verified
	 */
	public static void ensureNotNull(Object object) {
		if (object == null) {
			throw new IllegalArgumentException();
		}
	}

	/**
	 * Throws an {@link IllegalArgumentException} if the passed object is
	 * {@code null} and adds the passed text to the exception.
	 * 
	 * @param object
	 *            object which is verified
	 * @param text
	 *            the text which is added to the exception
	 */
	public static void ensureNotNull(Object object, String text) {
		if (object == null) {
			throw new IllegalArgumentException(text);
		}
	}

	/**
	 * Throws an {@link IllegalArgumentException} if the passed object is empty.
	 * 
	 * @param str
	 *            String which is verified
	 */
	public static void ensureNotEmpty(String str) {
		if (str.isEmpty()) {
			throw new IllegalArgumentException();
		}
	}

	/**
	 * Throws an {@link IllegalArgumentException} if the passed String is empty
	 * and adds the passed text to the exception.
	 * 
	 * @param str
	 *            String which is verified
	 * @param text
	 *            the text which is added to the exception
	 */
	public static void ensureNotEmpty(String str, String text) {
		if (str.isEmpty()) {
			throw new IllegalArgumentException(text);
		}
	}
}
